<template>
  <div class="news-box">
    <el-form :model="form" ref="formRef" :rules="rules" label-width="180px" class="demo-ruleForm">
      <el-form-item label="每单最少回收总数:" prop="zuishaoshuji">
        <el-input type="text" placeholder="请输入内容" size="large" v-model="form.zuishaoshuji" maxlength="50" show-word-limit> </el-input>
      </el-form-item>
      <el-form-item label="每单最小总金额:" prop="zuishaoprice">
        <el-input type="text" placeholder="请输入内容" size="large" v-model="form.zuishaoprice" maxlength="50" show-word-limit> </el-input>
      </el-form-item>
      <el-form-item label="单次最大提现金额:" prop="max_tixian_money">
        <el-input type="text" placeholder="请输入内容" size="large" v-model="form.max_tixian_money" maxlength="50" show-word-limit> </el-input>
      </el-form-item>
      <el-form-item label="自动通过最小金额:" prop="yue_tixian_biaozhun">
        <el-input type="text" placeholder="请输入内容" size="large" v-model="form.yue_tixian_biaozhun" maxlength="50" show-word-limit> </el-input>
      </el-form-item>
      <el-form-item label="自动通过每月最少次数:" prop="yue_tixian_cizhu">
        <el-input type="text" placeholder="请输入内容" size="large" v-model="form.yue_tixian_cizhu" maxlength="50" show-word-limit> </el-input>
      </el-form-item>
      <el-form-item label="单本书籍回收最大数量:" prop="order_max_book_count">
        <el-input type="text" placeholder="请输入内容" size="large" v-model="form.order_max_book_count" maxlength="50" show-word-limit> </el-input>
      </el-form-item>
      <el-form-item label="单次订单回收最大总数量:" prop="order_max_count">
        <el-input type="text" placeholder="请输入内容" size="large" v-model="form.order_max_count" maxlength="50" show-word-limit> </el-input>
      </el-form-item>
    </el-form>
    <div class="bottom-btn">
      <el-button type="primary" @click="editFun">确定</el-button>
    </div>
  </div>
</template>
<script setup>
import { computed, onMounted, ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { getServerConfig, updateServerConfig } from '@api/book'
import { useUserStore } from '@/pinia/user'
import { ElMessage } from 'element-plus'

const userStore = useUserStore()

const router = useRouter()

// *********************************************列表
const form = ref({
  zuishaoshuji: '',
  zuishaoprice: '',
  max_tixian_money: '',
  order_max_book_count: '',
  order_max_count: ''
})

const rules = reactive({
  zuishaoshuji: [{ required: true, message: '每个订单最少书籍回收总数不能为空!', trigger: 'blur' }],
  zuishaoprice: [{ required: true, message: '每个订单最小总金额不能为空!', trigger: 'blur' }],
  max_tixian_money: [{ required: true, message: '单次最大提现金额不能为空!', trigger: 'blur' }]
})

//获取列表
async function getDetail() {
  let res = await getServerConfig()
  if (res.code == 200) {
    form.value = res.data
  }
}

//添加文章
const editFun = async () => {
  const { zuishaoshuji, zuishaoprice, max_tixian_money, yue_tixian_biaozhun, yue_tixian_cizhu, order_max_book_count, order_max_count } = form.value

  const res = await updateServerConfig({
    zuishaoshuji,
    zuishaoprice,
    max_tixian_money,
    yue_tixian_biaozhun,
    yue_tixian_cizhu,
    order_max_book_count,
    order_max_count
  })

  if (res.code == 200) {
    ElMessage({
      message: '操作成功!',
      type: 'success'
    })
    getDetail()
  }
}

onMounted(() => {
  getDetail()
})
</script>
<style lang="scss" scoped>
.news-box {
  width: 500px;

  .bottom-btn {
    padding-left: 180px;
    margin-top: 30px;
  }
}
</style>
